<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch" label-width="68px"
      @submit.native.prevent>
      <el-form-item label="时间区域">
        <el-date-picker v-model="dateRange" value-format="yyyy-MM-dd" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" border>
      <el-table-column label="资产名称" align="center" prop="assetsName" />
      <el-table-column label="资产类型" align="center" prop="assetsType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_assets_type" :value="scope.row.assetsType" />
        </template>
      </el-table-column>
      <el-table-column label="资产型号" align="center" prop="assetsModel" />
      <el-table-column label="数量" align="center" prop="numberCount" />
      <el-table-column label="购置总成本" align="center">
        <template slot-scope="scope">
          {{ toMoney(scope.row.bulMoney * scope.row.numberCount) }}
        </template>
      </el-table-column>
      <el-table-column label="维修总金额" align="center" prop="repairMoney">
        <template slot-scope="scope">
          {{ toMoney(scope.row.repairMoney) }}
        </template>
      </el-table-column>
      <el-table-column label="折旧总金额" align="center" prop="depreciationMoney">
        <template slot-scope="scope">
          {{ toMoney(scope.row.depreciationMoney) }}
        </template>
      </el-table-column>
      <el-table-column label="增值总金额" align="center" prop="addedMoney">
        <template slot-scope="scope">
          {{ toMoney(scope.row.addedMoney) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleView(scope.row)">查看明细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 资产明细 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <assets-view-details v-if="open" :assetsId="assetsId" :assetsName="assetsName"></assets-view-details>
    </el-dialog>
  </div>
</template>

<script>
import { totalAssetsStatistics } from '@/api/cld/assets'

import assetsViewDetails from './assetsViewDetails.vue';
export default {
  components: { assetsViewDetails },
  dicts: ['cld_assets_type'],
  name: "assetsTotal",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 时间区间
      dateRange: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 列表数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      queryData: [],
      assetsId: null,
      assetsName: null
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      totalAssetsStatistics(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryData = this.dateRange;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryData = this.dateRange;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 查看明细
    handleView(row) {
      this.assetsId = row.assetsId;
      this.title = row.assetsName;
      this.assetsName = row.assetsName;
      this.open = true;
    },
  }
};
</script>
<style scoped>
.el-select {
  width: 100%;
}
</style>
